package com.gfxy.modules.excel;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;

/**
 * @Author: JinChongLi
 * @Description:
 * @Date: Created in 16:37 2021/10/13
 * @Modified By:
 */
@Service
public class TemplateUtil {

    private static final Log log = LogFactory.getLog(TemplateUtil.class);

    @Value(value = "${jeecg.path.template}")
    private String template;

    public static final String ZYQJS ="1.专业群建设.xlsx";
    public static final String KXJS = "2.课程建设.xlsx";
    public static final String ZYKJS = "3.资源库建设.xlsx";
    public static final String SXJD = "4.实训基地建设.xlsx";
    public static final String YXJC = "5.优秀教材.xlsx";
    public static final String JXMS = "6.教学名师.xlsx";
    public static final String JXCG = "7.教学成果奖.xlsx";
    public static final String KCCXDS ="8.课程创新大赛.xlsx";
    public static final String KXSZ = "9.课程思政大练兵.xlsx";
    public static final String JXNL = "10.教学能力大赛.xlsx";
    public static final String KLW = "11.互联网+大赛.xlsx";
    public static final String JXTD="12.教学团队.xlsx";
    public static final String ZYHY = "13.重要会议发言或典型案例.xlsx";
    public static final String SDYX = "14.1+x试点与运行.xlsx";
    public static final String XZYSB ="15.新专业申报.xlsx";
    public static final String RCPY = "16.人才培养方案.xlsx";
    public static final String XYPXJD ="17.校外实训教学基地建设.xlsx";
    public static final String ZGKJ = "18.众创空间.xlsx";
    public static final String XZW ="19.行职委任职.xlsx";
    public static final String JGXM = "20.教改项目.xlsx";
    public static final String QNJSJKBS ="22.青年讲师讲课比赛.xlsx";
    public static final String YSZP = "23.艺术作品获全国美展.xlsx";
    public static final String JNDS = "24.技能大赛.xlsx";
    public static final String YTSX = "25.体育赛项.xlsx";
    public static final String ZHRY = "26.综合荣誉类.xlsx";
    public static final String DXRY = "27.单项荣誉.xlsx";

    public static final String CJRH = "28.产教融合.xlsx";
    public static final String CBJNDS = "29.承办技能大赛.xlsx";
    // public static final String CXCY = "创新创业大赛.xlsx";

    public static final String ZYYXSZTSJH = "职业院校素质能力提升.xlsx";

    public static final String BZSC = "标准输出.xlsx";

    public static final String LXSPY = "留学生培养.xlsx";
    public static final String FDYSZNLDS = "辅导员素质能力大赛.xlsx";

    public static final String QTXMHXZB = "其他项目(核心指标).xlsx";

    public static final String QTXMJXKH = "其他项目(绩效考核).xlsx";
    public void template(HttpServletResponse response, String fileName) throws IOException {

        File file = null;
        InputStream inputStream = null;
        OutputStream out = null;
        try {
            file = new File(template + File.separator + fileName);

            System.out.println(file.getAbsolutePath());
            String _filename = fileName;
            inputStream = new FileInputStream(file);
            response.setContentType("application/force-download");
            out = response.getOutputStream();
            response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(_filename, "UTF-8"));
            response.setContentType("application/json;charset=utf-8");
            int b = 0;
            byte[] buffer = new byte[1000000];
            while (b != -1) {
                b = inputStream.read(buffer);
                if (b != -1) {
                    out.write(buffer, 0, b);
                }
            }
        } catch (IOException e) {
            log.error(e.getLocalizedMessage(), e);
        } finally {
            if(inputStream != null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    log.error(e.getLocalizedMessage(), e);
                }
            }

        }






    }
}
